﻿////#include <iostream>
////using namespace std;
////
////class Person
////{
////public:
////	virtual Person& GetTicket(void)
////	{
////		cout << "成人票：全价"<<endl;
////		return *this;
////	}
////	virtual ~Person()
////	{
////		cout << "~Person" << endl;
////	}
////};
////
////class Stu :public Person
////{
////public:
////	virtual Stu& GetTicket(void)override
////	{
////		return *this;
////	}//没有完成对基类虚函数的重写，即使该函数本身也是虚函数
////	/*{
////		cout << "学生票：半价" << endl;
////		return *this;
////	}*/
////	~Stu()
////	{
////		cout << "~Stu" << endl;
////	}
////};
////class A :public Stu
////{
////public:
////	A& GetTicket(void)
////	{
////		cout << "A" << endl;
////		return *this;
////	}
////	~A()
////	{
////		cout << "~A" << endl;
////	}
////};
////class Solder :public Person
////{
////public:
////	virtual Solder& GetTicket(void)override//没有完成对基类虚函数的重写，即使该函数本身也是虚函数
////	{
////		cout << "军人票：全价" << endl;
////		return *this;
////	}
////	~Solder()
////	{
////		cout << "~Solder" << endl;
////	}
////};
////
//////void fuc1(Person* p)
//////{
//////	p->GetTicket();
//////}
//////void fuc2(Person& p)
//////{
//////	p.GetTicket();
//////}
//////void fuc3(Person p)
//////{
//////	p.GetTicket();
//////}
////int main()
////{
////	//Person* p = new Person;
////	//Person* pt = new Stu;
////	Person* ptr = new A;
////	A a;
////	a.Person::GetTicket();
////	//Person* ptr = new Solder;
////	ptr->GetTicket();
////	a.GetTicket();
////	
////	delete ptr;
////
////	//int* arr = new int[6];
////	//delete[] arr;
////	//int t = 10;
////	//arr = &t;
////	//*arr = 20;
////	//Person a;
////	//Stu b;
////	//Solder c;
////
////	//Person* p = new Person;
////	//Person* q = new Stu;
////	//delete p;
////	//delete q;
////	//p = &b;
////	/*fuc3(a);
////	fuc3(b);
////	fuc3(c);*/
////	/*fuc1(&a);
////	fuc1(&b);
////	fuc1(&c);
////	cout << endl;
////	fuc2(a);
////	fuc2(b);
////	fuc2(c);*/
////
////	return 0;
////}
//
//#include <iostream>
//using namespace std;
//class Car
//{
//public:
//	virtual void wheel()
//	{
//		cout << "Car" << endl;
//	}
//	
//	virtual void wheel2()
//	{
//		cout << "CAr2" << endl;
//	}
//	void wheel3()
//	{
//		cout << "CAr3" << endl;
//	}
//protected:
//	int _a = 0;
//};
//
//
//class CarA
//{
//public:
//	virtual void wheel()
//	{
//		cout << "CarA1" << endl;
//	}
//
//	virtual void wheel2()
//	{
//		cout << "CArA2" << endl;
//	}
//	void wheel3()
//	{
//		cout << "CAr3" << endl;
//	}
//protected:
//	int _a = 0;
//};
//
//
//class Ben :public Car,public CarA
//{
//public:
//	Ben()
//	{
//		Car::_a = 10;
//		CarA::_a = 10;
//	}
//	virtual void wheel()
//	{
//		cout << "Ben" << endl;
//	}
//	virtual void wheel4()
//	{
//		cout << "Ben4" << endl;
//	}
//	virtual void wheel5()
//	{
//		cout << "Ben5" << endl;
//	}
//};
//void print(int* ptr)
//{
//	cout << endl;
//	for (int i = 0; ptr[i] != 0; i++)
//	{
//		printf("v[%d]:0x%x\n", i, ptr[i]);
//	}
//	cout << endl;
//
//}
//int main()
//{
//	CarA a;
//	Car b;
//	Ben c;
//	int* p1 = (int*)(*((int*)&a));//可以得到_vfptr的值,就是虚表的首地址
//	print(p1);
//
//	int* p2 = (int*)(*((int*)&b));//可以得到_vfptr的值,就是虚表的首地址
//	print(p2);
//
//	int* p3 = (int*)(*((int*)&c));//可以得到_vfptr的值,就是虚表的首地址
//	print(p3);
//
//
// 	return 0;
//}
////Car a;
//	//Ben b;
//	//Car* p = &a;
//	//Car* pt = &b;
//	//int* ptr = (int*)(*((int*)p));
//	//cout << "基类虚表:"<<endl;
//	//while (*((int*)(*ptr)))
//	//{
//	//	//printf("0x%x\n", *ptr);
//	//	cout << "0x" << (int*)*((int*)(*ptr)) << endl;
//	//	ptr++;
//	//}
//	//int* ptr1 = (int*)pt;
//	//cout << "派生类虚表:" << endl;
//	//while (*ptr1)
//	//{
//	//	//printf("0x%x\n", *ptr);
//	//	cout << "0x" << (int*)(*ptr1) << endl;
//	//	ptr1++;
//	//}
///*	const char* str = "hello";
//	static int d = 0;
//	Car* p;
//	Ben b;
//	p = &b;
//	int a = 0;
//	int* c = new int;
//	cout << "栈：    " << &a << endl;
//	cout << "堆：    " << (void*)c << endl;
//	cout << "静态区：" << &d << endl;
//	cout << "虚表:   " << (void*)*((int*)p) << endl;;
//	cout << "代码段: " << (int*)str << endl;*/



#include <iostream>
using namespace std;
class A
{
public:
	A()
		:_iVal(0) 
	{ test(); }
	virtual void func() {
		std::cout << _iVal << ' ';
	}
	void test()
	{
		func();
	}
public:
	int _iVal;
};
class B : public A
{
public:
	B()
	{
		test();
	}
	virtual void func()
	{
		++_iVal;
		cout << _iVal << " ";
	}
};
int main(int argc, char* argv[])
{
	A* p= new B;
	p->test();
	return 0;
}